<?php
namespace App\Listeners\Subscribers;

use App\Listeners\CacheHitListener;
use App\Listeners\CacheKeyForgottenListener;
use App\Listeners\CacheKeyWrittenListener;
use App\Listeners\CacheMissedListener;
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Cache\Events\KeyForgotten;
use Illuminate\Cache\Events\KeyWritten;

/**
 * 缓存事件订阅器
 * Date: 2017-04-04
 */
class CacheEventSubscriber
{

    public function subscribe($events)
    {
        /**
         * 缓存命中
         */
        $events->listen(
            CacheHit::class,
            CacheHitListener::class
        );

        /**
         * 缓存丢失
         */
        $events->listen(
            CacheMissed::class,
            CacheMissedListener::class
        );

        /**
         * 删除缓存
         */
        $events->listen(
            KeyForgotten::class,
            CacheKeyForgottenListener::class
        );

        /**
         * 写入缓存
         */
        $events->listen(
            KeyWritten::class,
            CacheKeyWrittenListener::class
        );
    }

}